## ======================================================================
## resources
## ======================================================================

resource_types:
- name: gcs
  type: registry-image
  source:
    repository: frodenas/gcs-resource

resources:
- name: gporca-commits-to-test
  type: git
  source:
    branch: test-gpdb-6X
    private_key: ((qp/slack-trigger-git-key))
    uri: ((slack-trigger-git-remote))

- name: gpdb6-centos7-build
  type: registry-image
  source:
    repository: gcr.io/data-gpdb-public-images/gpdb6-centos7-build
    tag: latest

- name: gpdb6-centos7-test
  type: registry-image
  source:
    repository: gcr.io/data-gpdb-public-images/gpdb6-centos7-test

- name: libquicklz-centos7
  type: gcs
  source:
    bucket: ((gcs-bucket))
    json_key: ((qp/concourse-gcs-resources-service-account-key))
    regexp: gp-internal-artifacts/centos7/libquicklz-(1\.5\.0-.*)-1.el7.x86_64.rpm

- name: libquicklz-devel-centos7
  type: gcs
  source:
    bucket: ((gcs-bucket))
    json_key: ((qp/concourse-gcs-resources-service-account-key))
    regexp: gp-internal-artifacts/centos7/libquicklz-devel-(1\.5\.0-.*)-1.el7.x86_64.rpm

- name: libsigar-centos7
  type: gcs
  source:
    bucket: ((gcs-bucket))
    json_key: ((qp/concourse-gcs-resources-service-account-key))
    regexp: gp-internal-artifacts/centos7/sigar-rhel7_x86_64-(1\.6\.5-.*).targz

- name: python-centos7
  type: gcs
  source:
    bucket: ((gcs-bucket))
    json_key: ((qp/concourse-gcs-resources-service-account-key))
    regexp: gp-internal-artifacts/centos7/python-(2\.7\.12-.*).tar.gz

- name: postgres_for_fdw
  type: gcs
  source:
    bucket: ((gcs-bucket))
    json_key: ((qp/concourse-gcs-resources-service-account-key))
    regexp: gp-internal-artifacts/postgres-fdw-dependencies/postgresql-(10.4).tar.gz

jobs:
- name: compile_and_test_gpdb
  max_in_flight: 10
  plan:
  - in_parallel:
    - get: gporca-commits-to-test
      trigger: true
      version: every
    - get: gpdb6-centos7-build
    - get: gpdb6-centos7-test
    - get: libquicklz-installer
      resource: libquicklz-centos7
    - get: libquicklz-devel-installer
      resource: libquicklz-devel-centos7
    - get: libsigar-installer
      resource: libsigar-centos7
    - get: python-tarball
      resource: python-centos7
    - get: postgres_for_fdw
      params:
        unpack: true

  - do:
    - task: init gpdb_src
      image: gpdb6-centos7-build
      config:
        platform: linux
        run:
          path: bash
          args:
          - -c
          - |
            BRANCH=$(cut -d, -f1 gporca-commits-to-test/gpdb_remote_info.txt)
            REMOTE=$(cut -d, -f2 gporca-commits-to-test/gpdb_remote_info.txt)
            git clone -b $BRANCH --single-branch $REMOTE gpdb_src &&
            cd gpdb_src &&
            git fetch https://github.com/greenplum-db/gpdb.git --tags &&
            git submodule update --init --recursive
        inputs: [{ name: gporca-commits-to-test }]
        outputs: [{ name: gpdb_src }]
    - task: compile_gpdb_centos7
      file: gpdb_src/concourse/tasks/compile_gpdb.yml
      image: gpdb6-centos7-build
      params:
        CONFIGURE_FLAGS: ((configure_flags_with_extensions))
        TARGET_OS: centos
        TARGET_OS_VERSION: 7
        BLD_TARGETS: "clients loaders"
      timeout: 30m


    - in_parallel:
      - task: icw_planner_centos7
        file: gpdb_src/concourse/tasks/ic_gpdb.yml
        image: gpdb6-centos7-test
        input_mapping:
          bin_gpdb: gpdb_artifacts
        params:
          MAKE_TEST_COMMAND: PGOPTIONS='-c optimizer=off' installcheck-world
          TEST_OS: centos
          CONFIGURE_FLAGS: ((configure_flags))
        timeout: 3h

      - task: icw_gporca_centos7
        file: gpdb_src/concourse/tasks/ic_gpdb.yml
        image: gpdb6-centos7-test
        input_mapping:
          bin_gpdb: gpdb_artifacts
        params:
          MAKE_TEST_COMMAND: PGOPTIONS='-c optimizer=on' installcheck-world
          TEST_OS: centos
          CONFIGURE_FLAGS: ((configure_flags))
        timeout: 5h

      - task: icw_gporca_memory_centos7
        file: gpdb_src/concourse/tasks/ic_gpdb.yml
        image: gpdb6-centos7-test
        input_mapping:
          bin_gpdb: gpdb_artifacts
        params:
          MAKE_TEST_COMMAND: PGOPTIONS='-c optimizer=on' installcheck-world
          TEST_OS: centos
          CONFIGURE_FLAGS: ((configure_flags))
          BLDWRAP_POSTGRES_CONF_ADDONS:
            - optimizer_use_gpdb_allocators=off
        timeout: 5h

      - task: unit_tests_gporca_centos7
        file: gpdb_src/concourse/tasks/unit_tests_gporca.yml
        image: gpdb6-centos7-build
        timeout: 1h

      - task: check_format
        file: gpdb_src/concourse/tasks/check_format.yml
